#include "loginwindow.h"
#include "ui_loginwindow.h"
#include <QMessageBox>

LoginWindow::LoginWindow(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::LoginWindow)
{
    ui->setupUi(this);
    // 设置默认账号密码
    ui->userEdit->setText("100");
    ui->passEdit->setText("100");
}

LoginWindow::~LoginWindow()
{
    delete ui;
}

// 登录按钮
void LoginWindow::on_loginBtn_clicked()
{
    QString user = ui->userEdit->text();
    QString pass = ui->passEdit->text();
    
    if (user.isEmpty() || pass.isEmpty()) {
        QMessageBox::warning(this, "错误", "用户名和密码不能为空");
        return;
    }
    
    // 验证登录：默认账号或已注册账号
    if ((user == "100" && pass == "100") || 
        (user == registeredUser && pass == registeredPass)) {
        QMessageBox::information(this, "成功", "登录成功！");
        this->accept();
    } else {
        QMessageBox::warning(this, "错误", "用户名或密码错误");
    }
}

// 注册按钮
void LoginWindow::on_registerBtn_clicked()
{
    QString user = ui->userEdit->text();
    QString pass = ui->passEdit->text();
    
    if (user.isEmpty() || pass.isEmpty()) {
        QMessageBox::warning(this, "错误", "用户名和密码不能为空");
        return;
    }
    
    registeredUser = user;
    registeredPass = pass;
    QMessageBox::information(this, "成功", "注册成功，请登录！");
}
